﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace SCS.DAL
{
	/// <summary>
	/// 数据访问类:JX_Semester
	/// </summary>
	public partial class JX_Semester
	{
		public JX_Semester()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(SCS.Model.JX_Semester model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.XQMC != null)
			{
				strSql1.Append("XQMC,");
				strSql2.Append("'"+model.XQMC+"',");
			}
			if (model.GUID != null)
			{
				strSql1.Append("GUID,");
				strSql2.Append(""+model.GUID+",");
			}
			if (model.KSRQ != null)
			{
				strSql1.Append("KSRQ,");
				strSql2.Append("'"+model.KSRQ+"',");
			}
			if (model.JSRQ != null)
			{
				strSql1.Append("JSRQ,");
				strSql2.Append("'"+model.JSRQ+"',");
			}
			if (model.XND != null)
			{
				strSql1.Append("XND,");
				strSql2.Append(""+model.XND+",");
			}
			if (model.XQH != null)
			{
				strSql1.Append("XQH,");
				strSql2.Append(""+model.XQH+",");
			}
			if (model.CurrentXQ != null)
			{
				strSql1.Append("CurrentXQ,");
				strSql2.Append(""+model.CurrentXQ+",");
			}
			if (model.CurrentPK != null)
			{
				strSql1.Append("CurrentPK,");
				strSql2.Append(""+model.CurrentPK+",");
			}
			if (model.CurrentXK != null)
			{
				strSql1.Append("CurrentXK,");
				strSql2.Append(""+model.CurrentXK+",");
			}
			if (model.Mark != null)
			{
				strSql1.Append("Mark,");
				strSql2.Append(""+model.Mark+",");
			}
			if (model.SKZS != null)
			{
				strSql1.Append("SKZS,");
				strSql2.Append(""+model.SKZS+",");
			}
			strSql.Append("insert into JX_Semester(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(SCS.Model.JX_Semester model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JX_Semester set ");
			if (model.XQMC != null)
			{
				strSql.Append("XQMC='"+model.XQMC+"',");
			}
			if (model.GUID != null)
			{
				strSql.Append("GUID="+model.GUID+",");
			}
			if (model.KSRQ != null)
			{
				strSql.Append("KSRQ='"+model.KSRQ+"',");
			}
			else
			{
				strSql.Append("KSRQ= null ,");
			}
			if (model.JSRQ != null)
			{
				strSql.Append("JSRQ='"+model.JSRQ+"',");
			}
			else
			{
				strSql.Append("JSRQ= null ,");
			}
			if (model.XND != null)
			{
				strSql.Append("XND="+model.XND+",");
			}
			if (model.XQH != null)
			{
				strSql.Append("XQH="+model.XQH+",");
			}
			if (model.CurrentXQ != null)
			{
				strSql.Append("CurrentXQ="+model.CurrentXQ+",");
			}
			if (model.CurrentPK != null)
			{
				strSql.Append("CurrentPK="+model.CurrentPK+",");
			}
			if (model.CurrentXK != null)
			{
				strSql.Append("CurrentXK="+model.CurrentXK+",");
			}
			if (model.Mark != null)
			{
				strSql.Append("Mark="+model.Mark+",");
			}
			if (model.SKZS != null)
			{
				strSql.Append("SKZS="+model.SKZS+",");
			}
			else
			{
				strSql.Append("SKZS= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JX_Semester ");
			strSql.Append(" where " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_Semester GetModel()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" XQMC,GUID,KSRQ,JSRQ,XND,XQH,CurrentXQ,CurrentPK,CurrentXK,Mark,SKZS ");
			strSql.Append(" from JX_Semester ");
			strSql.Append(" where " );
			SCS.Model.JX_Semester model=new SCS.Model.JX_Semester();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.JX_Semester DataRowToModel(DataRow row)
		{
			SCS.Model.JX_Semester model=new SCS.Model.JX_Semester();
			if (row != null)
			{
				if(row["XQMC"]!=null)
				{
					model.XQMC=row["XQMC"].ToString();
				}
				if(row["GUID"]!=null && row["GUID"].ToString()!="")
				{
					model.GUID=int.Parse(row["GUID"].ToString());
				}
				if(row["KSRQ"]!=null && row["KSRQ"].ToString()!="")
				{
					model.KSRQ=DateTime.Parse(row["KSRQ"].ToString());
				}
				if(row["JSRQ"]!=null && row["JSRQ"].ToString()!="")
				{
					model.JSRQ=DateTime.Parse(row["JSRQ"].ToString());
				}
				if(row["XND"]!=null && row["XND"].ToString()!="")
				{
					model.XND=int.Parse(row["XND"].ToString());
				}
				if(row["XQH"]!=null && row["XQH"].ToString()!="")
				{
					model.XQH=int.Parse(row["XQH"].ToString());
				}
				if(row["CurrentXQ"]!=null && row["CurrentXQ"].ToString()!="")
				{
					model.CurrentXQ=int.Parse(row["CurrentXQ"].ToString());
				}
				if(row["CurrentPK"]!=null && row["CurrentPK"].ToString()!="")
				{
					model.CurrentPK=int.Parse(row["CurrentPK"].ToString());
				}
				if(row["CurrentXK"]!=null && row["CurrentXK"].ToString()!="")
				{
					model.CurrentXK=int.Parse(row["CurrentXK"].ToString());
				}
				if(row["Mark"]!=null && row["Mark"].ToString()!="")
				{
					model.Mark=int.Parse(row["Mark"].ToString());
				}
				if(row["SKZS"]!=null && row["SKZS"].ToString()!="")
				{
					model.SKZS=decimal.Parse(row["SKZS"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select XQMC,GUID,KSRQ,JSRQ,XND,XQH,CurrentXQ,CurrentPK,CurrentXK,Mark,SKZS ");
			strSql.Append(" FROM JX_Semester ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" XQMC,GUID,KSRQ,JSRQ,XND,XQH,CurrentXQ,CurrentPK,CurrentXK,Mark,SKZS ");
			strSql.Append(" FROM JX_Semester ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JX_Semester ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.User_ID desc");
			}
			strSql.Append(")AS Row, T.*  from JX_Semester T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

